function yMinusPicker(exp) {
  $(exp).datetimepicker({
    format: "hh:ii",
    minuteStep: 1,
    autoclose: true,
    maxView: "day",
    minView: "hour",
    startView: "day",
    todayBtn: "link",
    language: "zh-CN"
  });
//    .on('hide', function (ev) {
//      $(exp + " input").blur();
//    });
}

function yTimePicker(exp) {
  $(exp).datetimepicker({
    format: "hh:ii:ss",
    minuteStep: 1,
    autoclose: true,
    maxView: "day",
    minView: "minus",
    startView: "day",
    todayBtn: "link",
    language: "zh-CN"
  });
//    .on('hide', function (ev) {
//      $(exp + " input").blur();
//    });
}

function yDatePicker(exp) {
  $(exp).datetimepicker({
    format: "yyyy-mm-dd",
    minuteStep: 1,
    autoclose: true,
    minView: "month",
    todayBtn: "link",
    language: "zh-CN"
  });
//    .on('hide', function (ev) {
//      $(exp + " input").blur();
//    });
}

function yDateMinusPicker(exp) {
  $(exp).datetimepicker({
    format: "yyyy-mm-dd hh:ii",
    minuteStep: 1,
    autoclose: true,
    minView: "hour",
    todayBtn: "link",
    language: "zh-CN"
  });
//  .on('hide', function (ev) {
//   $(exp + " input").blur();
//   });
}

function yDateTimePicker(exp) {
  $(exp).datetimepicker({
    format: "yyyy-mm-dd hh:ii:ss",
    minuteStep: 1,
    autoclose: true,
    todayBtn: "link",
    language: "zh-CN"
  });
//  .on('hide', function (ev) {
//   $(exp + " input").blur();
//   });
}

function formError() {
  var control = arguments[0];
  var msg = "";
  if (arguments.length > 1) msg = arguments[1];
  $(control).removeClass("has-success has-warning").addClass("has-error");
  $(control + " .help-block").html(msg);
}

/**
 * @param control div
 * @param msg 可选
 */
function formSuccess() {
  var control = arguments[0];
  var msg = "";
  if (arguments.length > 1) msg = arguments[1];
  $(control).removeClass("has-error has-warning").addClass("has-success");
  $(control + " .help-block").html(msg);
}

/**
 * @param control div
 * @param msg 可选
 */
function formWarning() {
  var control = arguments[0];
  var msg = "";
  if (arguments.length > 1) msg = arguments[1];
  $(control).removeClass("has-error has-success").addClass("has-warning");
  $(control + " .help-block").html(msg);
}

/**
 * @param control div
 * @param msg 可选
 */
function formInfo() {
  var control = arguments[0];
  var msg = "";
  if (arguments.length > 1) msg = arguments[1];
  $(control).removeClass("has-error has-success has-warning");
  $(control + " .help-block").html(msg);
}

function formClear(control) {
  $(control).removeClass("has-error has-warning has-success");
  $(control + " textarea").html("");
  $(control + " input").val("");
  $(control + " select").html("");
  $(control + " .help-block").html("");
}

function formDisabled() {
  var len = arguments.length;

  if (len == 0) {
    $("fieldset").attr("disabled", "disabled");
  } else {
    var exp = '';
    var i = 0;
    while (i < len) {
      exp = arguments[i]
      $(exp + " fieldset").attr("disabled", "disabled");
      i = i + 1;
    }
  }
}

function formRemove() {
  var len = arguments.length;

  if (len == 0) {
    $(".form-actions").remove();
    $(".edit-actions").remove();
  } else {
    var exp = '';
    var i = 0;
    while (i < len) {
      exp = arguments[i]
      $(exp + " .form-actions").remove();
      $(exp + " .edit-actions").remove();
      i = i + 1;
    }
  }

}

$(function () {
  $("select[multiple]").select2();

//  yDateMinusPicker(".data-dateminus");
//  yDatePicker(".data-date");
//  yMinusPicker(".data-minus");
//  yDateTimePicker(".data-datetime");
//  yTimePicker(".data-time");

//  imsDatepicker = $.datepicker.regional['zh-CN'];
//  imsDatepicker.timeFormat = "HH:mm:ss";
//  imsDatepicker.

  imsDatepicker = {
//    showOn:'button',
    dateFormat: "yy-mm-dd",
    timeFormat: "HH:mm:ss",
//    onSelect: function (dateText, inst) {
//      console.log(dateText, inst);
//    },
    onClose: function (dateText, inst) {
      //日期选择框不绑定和服务器响应的change事件
      //让隐藏框来触发change事件
      $('#' + this.id + '_hidden').val(dateText);
//      $('#' + this.id + '_hidden').blur();
    }
  }

});
